import Vue from 'vue'

Vue.config.productionTip = false

const modulesFiles = require.context('./components', true, /\.js$/)

const components = modulesFiles.keys().reduce((modules, modulePath) => {
  const value = modulesFiles(modulePath)
  modules.push(value.default);
  return modules
}, [])

// 将所有组件注册在Vue上
const install = function (Vue) {
  components.forEach(component => {
    Vue.component(component.name, component)
  })
}

if (typeof window !== 'undefined' && window.Vue) {
  install(window.Vue)
}

export default {
  install,
  ...components
}
